﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SYcwpb.ViewModels;
using SYcwpb.Helpers;

namespace SYcwpb.Views
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class InitializationClass : Window
    {
        CurrentRunningTrem t ;
        string _line;
        public InitializationClass()
        {
            InitializeComponent();
        }

        public InitializationClass(string line)
        {
            InitializeComponent();
            _line = line;
        }

        public InitializationClass(ref CurrentRunningTrem team)
        {
            InitializeComponent();
            t = team;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {

            try
            {
                if (cbxzb.SelectedIndex == -1 || cbxxb.SelectedIndex == -1 || cbxbb.SelectedIndex == -1 || cbxwb.SelectedIndex == -1)
                {
                    MessageBox.Show("请选择班次对应的车组！");
                }
                else
                {



                    string str = "delete from ClassTurn where line='" + _line + "';";
                    str += str + "INSERT INTO [ClassTurn]([line],[ctn_team],[ctn_cls_id])VALUES('" + _line + "','" + Convert.ToString(cbxxb.SelectedIndex + 1) + "','0');";
                    str += str + "INSERT INTO [ClassTurn]([line],[ctn_team],[ctn_cls_id])VALUES('" + _line + "','" + Convert.ToString(cbxbb.SelectedIndex + 1) + "','1')";
                    str += str + "INSERT INTO [ClassTurn]([line],[ctn_team],[ctn_cls_id])VALUES('" + _line + "','" + Convert.ToString(cbxwb.SelectedIndex + 1) + "','2')";
                    str += str + "INSERT INTO [ClassTurn]([line],[ctn_team],[ctn_cls_id])VALUES('" + _line + "','" + Convert.ToString(cbxzb.SelectedIndex + 1) + "','3')";
                    SqlDataLayer sqlHelper = new SqlDataLayer();
                    sqlHelper.ExecuteSql(str);

                    this.Close();

                }
            }
            catch (System.Exception ex)
            {
                MessageBoxHelper.ShowError(ex);
            }

          
        }
    }
}
